﻿#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;


class Solution
{
public:
    // 1218. 最长定差子序列
    int longestSubsequence(vector<int>& arr, int difference)
    {
        unordered_map<int, int> hash;
        hash[arr[0]] = 1;

        int ret = 1;
        for (int i = 1; i < arr.size(); i++)
        {
            hash[arr[i]] = hash[arr[i] - difference] + 1;
            ret = max(hash[arr[i]], ret);
        }
        return ret;
    }
};

int main()
{
    vector<int> v = { 1,5,7,8,5,3,4,2,1 };
    Solution().longestSubsequence(v, -2);

    return 0;
}